package Two;

import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoLabel;
import com.lovo.netCRM.component.LovoTable;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class BuyListFrame extends JFrame {
    private IBuy i = new BuyImpl();

    private LovoTable table = new LovoTable(this,new String[]{"编号","名字","单价","数量"},new String[]{"code","name","price","number"},
            "code");
    private int code;


    public BuyListFrame(int code){
        this.code = code;

        this.setLayout(null);
        this.init();

        this.setSize(400,500);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void init(){

//        System.out.println(code);

        i.updateNumber(code);

        showAll();

        table.setSizeAndLocation(50,60,300,300);
        LovoLabel label = new LovoLabel("购物车商品如下",20,20,this);
        LovoButton backButton = new LovoButton("返回",250,390,this);
        backButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new MainFrame();
            }
        });
    }
    private void showAll(){
        List<Commodity> l = i.showBuy();
        table.updateLovoTable(l);

    }



}
